#include "Database.h"

Database::Database()
{
    db = QSqlDatabase::database();

    // If database is invalid, one needs to be added
    if (!db.isValid())
    {
        // Connect to SQLite database
        db = QSqlDatabase::addDatabase("QSQLITE");

        db.setDatabaseName("users.db.sqlite");

        // Database login information
        // NOTE: Right now this is completely arbitrary
        db.setHostName("initech");
        db.setUserName("admin");
        db.setPassword("12345");

        open();
        QSqlQuery query;
        query.exec("CREATE DATABASE IF NOT EXISTS user_db");
        close();
    }
}

bool Database::open()
{
    return db.open();
}

void Database::close()
{
    db.close();
}
